package com.whimscrew.test.controller;

import com.whimscrew.test.constants.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("config")
public class ConfigController {


    @Autowired
    private StringRedisTemplate redisTemplate;

    @Autowired
    Config config;

    @GetMapping("/text")
    public String test(){
        String cacheKey = "config.text";
        redisTemplate.opsForValue().setIfAbsent(cacheKey , config.getText(), 1, TimeUnit.MINUTES);
        return    redisTemplate.opsForValue().get(cacheKey) ;
    }


}
